home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / structkeyexists.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  1.7 KB  |  40 lines

  1. <!--- This view-only example illustrates usage
  2.       of StructKeyExists. --->
  3. <P>This file is similar to addemployee.cfm, which is called
  4. by StructNew, StructClear, and StructDelete. To test this file,
  5. copy the <cfelseif> statement to the appropriate place
  6. in addemployee.cfm. It is an example of a custom tag used 
  7. to add employees. Employee information is passed through the 
  8. employee structure (the EMPINFO attribute). 
  9. <P>
  10. To run this snippet
  11. under UNIX, you must add employee ID generation logic.
  12. <!--- 
  13. <cfswitch expression="#ThisTag.ExecutionMode#">
  14.    <cfcase value="start">
  15.       <CFIF StructIsEmpty(attributes.EMPINFO)>
  16.         <CFOUTPUT>Error. No employee data was passed.</cfoutput>
  17.           <CFEXIT METHOD="ExitTag">
  18.         <cfelseif NOT StructKeyExists(attributes.EMPINFO, "department")>
  19.           <cfscript>StructUpdate(attributes.EMPINFO, "department", "Unassigned")</cfscript>
  20.           <CFEXIT METHOD="ExitTag">
  21.         <cfelse>
  22.           <CFQUERY NAME="AddEmployee" DATASOURCE="cfsnippets">
  23.             INSERT INTO Employees(FirstName, LastName, Email, Phone, Department)
  24.               VALUES 
  25.                 <CFOUTPUT>
  26.                   (
  27.                     '#StructFind(attributes.EMPINFO, "firstname")#' ,
  28.                     '#StructFind(attributes.EMPINFO, "lastname")#' ,
  29.                     '#StructFind(attributes.EMPINFO, "email")#' ,
  30.                     '#StructFind(attributes.EMPINFO, "phone")#' ,
  31.                     '#StructFind(attributes.EMPINFO, "department")#'
  32.                    )
  33.                 </cfoutput> 
  34.           </cfquery>
  35.         </cfif>
  36.       <CFOUTPUT><HR>Employee Add Complete
  37.    </cfcase>
  38. </cfswitch> --->
  39.  
  40.